fix(parser): keep last occurrence of streaming message id within file (#110)#155
Open
ousamabenyounes wants to merge 1 commit intogetagentseal:mainfrom
Open
fix(parser): keep last occurrence of streaming message id within file (#110)#155ousamabenyounes wants to merge 1 commit intogetagentseal:mainfrom
ousamabenyounes wants to merge 1 commit intogetagentseal:mainfrom
Conversation
…getagentseal#110) Claude Code streams an assistant response across several JSONL writes that share the same `message.id`: an early `message_start` (empty content), optional mid- stream updates, and a final `message_stop` carrying the `tool_use` blocks plus authoritative usage. `groupIntoTurns` deduplicates by id keeping the FIRST occurrence, so `tool_use` (MCP, Agent, EnterPlanMode, …) and final token counts in the last entry were silently dropped. Add a within-file pre-pass `dedupeStreamingMessageIds` in `parseSessionFile` that keeps the LAST occurrence of each message id. Cross-file dedup against `seenMsgIds` in `groupIntoTurns` stays keep-first-seen (it serves a different purpose: avoiding double-counting when the same session appears under several project dirs). Adds `tests/parser-streaming-dedup.test.ts` covering streaming dedup, mixed user/assistant entries, no-id passthrough, and ordering between distinct ids. Co-Authored-By: Ora Studio <noreply@oratelecom.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #110.
Claude Code writes the same
message.idmultiple times to the session JSONL as a response streams in. Only the final write carries thetool_useblocks (MCP servers, Agent, EnterPlanMode, …) and the authoritative token counts. The existing dedup ingroupIntoTurnskeeps the first occurrence by id, so for every streamed turn:tool_useblocks for Agent / EnterPlanMode / Bash are droppedFix
Add a within-file pre-pass
dedupeStreamingMessageIdsinparseSessionFilethat keeps the last occurrence of eachmessage.id. The cross-file dedup ingroupIntoTurns(againstseenMsgIds) is correct for what it does — avoiding double-counting when the same session appears under multiple project dirs — and stays keep-first-seen.The two concerns are now handled separately:
parseSessionFile(new)groupIntoTurns(unchanged)Verification
tests/parser-streaming-dedup.test.tsfails on the unfixed code (verified by stashing the fix and re-running)npx tsc --noEmitclean{}-init maps insrc/parser.tsorsrc/providers/(semgrep guard)Files changed
src/parser.tsdedupeStreamingMessageIds; called fromparseSessionFilebeforegroupIntoTurnstests/parser-streaming-dedup.test.tsVibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)